package com.bao.work.work02;

import java.util.*;

/**
 * @author baoye
 * @date 2024-08-01/19:56
 */
public class Test {
    public static void main(String[] args) {
        List<Student> list=new LinkedList<>();
        Map<Integer,Student> map=new HashMap<>();
        list.add(new Student(1,"小菜",15,"男"));
        list.add(new Student(2,"中菜",45,"男"));
        list.add(new Student(3,"大菜",55,"男"));
        list.add(new Student(4,"老菜",65,"男"));
        list.add(new Student(5,"菜九",95,"男"));
        list.forEach(System.out::println);
        System.out.println("----------");
        listToMap(list,map);
        list.forEach(System.out::println);
        System.out.println("----------");
        map.forEach((key,value)-> System.out.println(value));
        System.out.println("----------");
        mapToList(map,list);
        map.forEach((key,value)-> System.out.println(value));
        System.out.println("----------");
        list.forEach(System.out::println);
        System.out.println("----------");
    }
    public static void listToMap(List<Student> list,Map<Integer,Student> map){
        map.clear();
        for (Student student : list) {
            map.put(student.getId(),student);
        }
        list.clear();
    }
    public static void mapToList(Map<Integer,Student> map,List<Student> list){
        list.clear();
        Collection<Student> students = map.values();
        list.addAll(students);
        map.clear();
    }
}
